Whenever the slice of a domU is set to 0, sedf_adjdom() sets extraweight
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 23 Feb 2006 10:31:01 +0000 (11:31 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 23 Feb 2006 10:31:01 +0000 (11:31 +0100)
to 0.  Later, in desched_extra_dom(), if the extrawight is not set, the
vcpu's score is calculated with this:

 /*domain was running in L1 extraq => score is inverse of
   utilization and is used somewhat incremental!*/
   if ( !inf->extraweight )
       /*NB: use fixed point arithmetic with 10 bits*/
       inf->score[EXTRA_UTIL_Q] = (inf->period << 10) /
           inf->slice;

Which can result in a divide by zero.

This changeset adds a comments and additional sanity check to prevent this
case from crashing Xen.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
xen/common/sched_sedf.c

index 45fdac3073ce65cdeaffe0e6c43af152fbe78aaa..d7a68262b14c892fa4218255c521af5825c0fa57 100644 (file)
@@ -1609,15 +1609,19 @@ static int sedf_adjdom(struct domain *p, struct sched_adjdom_cmd *cmd)
         else {
             /*time driven domains*/
             for_each_vcpu(p, v) {
-                /* sanity checking! */
-                if(cmd->u.sedf.slice > cmd->u.sedf.period )
+                /*
+                 * Sanity checking: note that disabling extra weight requires
+                 * that we set a non-zero slice.
+                 */
+                if ( (cmd->u.sedf.slice == 0) ||
+                     (cmd->u.sedf.slice > cmd->u.sedf.period) )
                     return -EINVAL;
                 EDOM_INFO(v)->weight = 0;
                 EDOM_INFO(v)->extraweight = 0;
                 EDOM_INFO(v)->period_orig = 
-                    EDOM_INFO(v)->period   = cmd->u.sedf.period;
+                    EDOM_INFO(v)->period  = cmd->u.sedf.period;
                 EDOM_INFO(v)->slice_orig  = 
-                    EDOM_INFO(v)->slice    = cmd->u.sedf.slice;
+                    EDOM_INFO(v)->slice   = cmd->u.sedf.slice;
             }
         }
         if (sedf_adjust_weights(cmd))